
package coms.delegates;

import EJB.EJBLocator;
import coms.dto.Publication;
import coms.dto.Review;
import coms.dto.User;
import coms.ejb.ReviewBeanRemote;
import java.util.List;

public class ReviewDelegate  implements IDelegate<Review> {
    ReviewBeanRemote bean;
    
    public void submitReview(Review review)
    {
        try{
            bean.update(review);
        }catch(Exception e)
        {
            System.out.println("e"+e.getMessage());
            e.printStackTrace();
        }
    }
    
    public ReviewDelegate()
    {
       try{
       bean =  EJBLocator.lookupReviewBean();
       }catch(Exception e)
       {
           e.printStackTrace();
       }
    }

    @Override
    public boolean create(Review review) throws Exception {
        Review reviewObj =  bean.create(review);
        if(reviewObj!=null)
            return true;
        else return false;
    }

    @Override
    public boolean update(Review review) throws Exception {
      return bean.update(review);
    }

    @Override
    public boolean delete(Review review) throws Exception {
        return bean.delete(review);
    }

    @Override
    public List<Review> search(Review review) throws Exception {
        return bean.search(review);
    }

    @Override
    public List<Review> findAll() throws Exception {
        return bean.findAll();
    }

    public List<Review> findByReviewer(User user) throws Exception {
        return bean.getByReviewer(user);
    }
    
    public List<Review> findByPublication(Publication publication) throws Exception {
        return bean.getByPublication(publication);
    }
    
    @Override
    public Review getById(int id) throws Exception {
        return bean.getById(id);
    }
}
